home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LT_CreateHandle.c < prev    next >
C/C++ Source or Header  |  1995-09-25  |  8KB  |  331 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. LayoutHandle * LIBENT
  10. LT_CreateHandle(REG(a0) struct Screen *Screen,REG(a1) struct TextAttr *Font)
  11. {
  12.     return(LT_CreateHandleTags(Screen,
  13.         LH_Font,    Font,
  14.     TAG_DONE));
  15. }
  16.  
  17.  
  18. /*****************************************************************************/
  19.  
  20.  
  21. LayoutHandle * __stdargs
  22. LT_CreateHandleTags(struct Screen *Screen,...)
  23. {
  24.     LayoutHandle    *Handle;
  25.     va_list      VarArgs;
  26.  
  27.     va_start(VarArgs,Screen);
  28.     Handle = LT_CreateHandleTagList(Screen,(struct TagItem *)VarArgs);
  29.     va_end(VarArgs);
  30.  
  31.     return(Handle);
  32. }
  33.  
  34.  
  35. /*****************************************************************************/
  36.  
  37.  
  38. LayoutHandle * LIBENT
  39. LT_CreateHandleTagList(REG(a0) struct Screen *Screen,REG(a1) struct TagItem *TagList)
  40. {
  41.     LayoutHandle    *Handle;
  42.     struct Screen    *PubScreen;
  43.     APTR         Pool;
  44.  
  45. #ifdef DO_PICKSHORTCUTS
  46.     ObtainSemaphore(<P_KeySemaphore);
  47.  
  48.     if(!LTP_KeysInitialized)
  49.     {
  50.         UBYTE          mapBuffer[2 * 3];
  51.         UBYTE          remapBuffer[10];
  52.         LONG          i;
  53.         struct InputEvent event;
  54.  
  55.         for(i = 0 ; i < 256; i++)
  56.         {
  57.             if((i > ' ' && i < 127) || i > 160)
  58.             {
  59.                 remapBuffer[0] = i;
  60.                 remapBuffer[1] = 0;
  61.  
  62.                 if(MapANSI(remapBuffer,1,mapBuffer,3,NULL) == 1)
  63.                 {
  64.                     if(!(mapBuffer[1] & ~QUALIFIER_SHIFT))
  65.                     {
  66.                         event . ie_NextEvent        = NULL;
  67.                         event . ie_Class        = IECLASS_RAWKEY;
  68.                         event . ie_SubClass        = 0;
  69.                         event . ie_Code         = mapBuffer[0];
  70.                         event . ie_Qualifier        = mapBuffer[1] & ~QUALIFIER_SHIFT;
  71.                         event . ie_position . ie_addr    = NULL;
  72.  
  73.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  74.                             LTP_Keys[0][i] = remapBuffer[0];
  75.  
  76.                         event . ie_NextEvent        = NULL;
  77.                         event . ie_Class        = IECLASS_RAWKEY;
  78.                         event . ie_SubClass        = 0;
  79.                         event . ie_Code         = mapBuffer[0];
  80.                         event . ie_Qualifier        = mapBuffer[1] | QUALIFIER_SHIFT;
  81.                         event . ie_position . ie_addr    = NULL;
  82.  
  83.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  84.                             LTP_Keys[1][i] = remapBuffer[0];
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.  
  90.         LTP_KeysInitialized = TRUE;
  91.     }
  92.  
  93.     ReleaseSemaphore(<P_KeySemaphore);
  94. #endif    /* DO_PICKSHORTCUTS */
  95.  
  96.     if(!Screen)
  97.     {
  98.         if(!(PubScreen = LockPubScreen(NULL)))
  99.             return(NULL);
  100.         else
  101.             Screen = PubScreen;
  102.     }
  103.     else
  104.         PubScreen = NULL;
  105.  
  106.     if(Pool = AsmCreatePool(MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR,1024,1024,SysBase))
  107.     {
  108.         if(Handle = AsmAllocPooled(Pool,sizeof(LayoutHandle),SysBase))
  109.         {
  110.             struct TagItem    *List,
  111.                     *Entry;
  112.             BOOLEAN         MenuGlyphs;
  113.  
  114.             MenuGlyphs = FALSE;
  115.  
  116.             Handle -> Pool            = Pool;
  117.             Handle -> Screen        = Screen;
  118.             Handle -> InitialTextAttr    = Screen -> Font;
  119.             Handle -> PubScreen        = PubScreen;
  120.             Handle -> PointBack        = Handle;
  121.             Handle -> GroupID        = PHANTOM_GROUP_ID;
  122.  
  123.             Handle -> ExitFlush        = TRUE;
  124.             Handle -> RawKeyFilter        = TRUE;
  125. #ifdef DO_CLONING
  126.             Handle -> CloningPermitted    = TRUE;
  127. #endif
  128.             Handle -> StandardEditHook    = &Handle -> DefaultEditHook;
  129.  
  130.             List = TagList;
  131.  
  132.             while(Entry = NextTagItem(&List))
  133.             {
  134.                 switch(Entry -> ti_Tag)
  135.                 {
  136.                     case LH_Font:
  137.  
  138.                         Handle -> InitialTextAttr = (struct TextAttr *)Entry -> ti_Data;
  139.                         break;
  140.  
  141.                     case LH_MenuGlyphs:
  142.  
  143.                         MenuGlyphs = Entry -> ti_Data;
  144.                         break;
  145.  
  146.                     case LH_Parent:
  147.  
  148.                         Handle -> Parent = (struct Window *)Entry -> ti_Data;
  149.                         break;
  150.  
  151.                     case LH_BlockParent:
  152.  
  153.                         Handle -> BlockParent = Entry -> ti_Data;
  154.                         break;
  155.  
  156.                     case LH_ExitFlush:
  157.  
  158.                         Handle -> ExitFlush = Entry -> ti_Data;
  159.                         break;
  160.  
  161.                     case LH_UserData:
  162.  
  163.                         Handle -> UserData = (APTR)Entry -> ti_Data;
  164.                         break;
  165.  
  166.                     case LH_RawKeyFilter:
  167.  
  168.                         Handle -> RawKeyFilter = Entry -> ti_Data;
  169.                         break;
  170.  
  171.                     case LH_AutoActivate:
  172.  
  173.                         Handle -> AutoActivate = Entry -> ti_Data;
  174.                         break;
  175.  
  176.                     case LH_LocaleHook:
  177.  
  178.                         Handle -> LocaleHook = (struct Hook *)Entry -> ti_Data;
  179.                         break;
  180.  
  181.                     case LH_EditHook:
  182.  
  183.                         Handle -> StandardEditHook = (struct Hook *)Entry -> ti_Data;
  184.                         break;
  185. #ifdef DO_CLONING
  186.                     case LH_CloningPermitted:
  187.  
  188.                         Handle -> CloningPermitted = Entry -> ti_Data;
  189.                         break;
  190.  
  191.                     case LH_SimpleClone:
  192.  
  193.                         if(Handle -> SimpleClone = Entry -> ti_Data)
  194.                             Handle -> ExactClone = FALSE;
  195.  
  196.                         break;
  197.  
  198.                     case LH_ExactClone:
  199.  
  200.                         if(Handle -> ExactClone = Entry -> ti_Data)
  201.                             Handle -> SimpleClone = FALSE;
  202.  
  203.                         break;
  204. #endif
  205.                 }
  206.             }
  207.  
  208. #ifdef DO_FRACTION_KIND
  209.             Handle -> FracEditHook . h_Entry    = (HOOKFUNC)LTP_FracEditRoutine;
  210.             Handle -> FracEditHook . h_Data     = Handle;
  211. #endif
  212.  
  213. #ifdef DO_PASSWORD_KIND
  214.             Handle -> PasswordEditHook . h_Entry    = (HOOKFUNC)LTP_PasswordEditRoutine;
  215.             Handle -> PasswordEditHook . h_Data    = Handle;
  216. #endif
  217.  
  218.             Handle -> DefaultEditHook . h_Entry    = (HOOKFUNC)LTP_DefaultEditRoutine;
  219.             Handle -> DefaultEditHook . h_Data    = Handle;
  220.  
  221.             Handle -> BackfillHook . h_Entry    = (HOOKFUNC)LTP_BackfillRoutine;
  222.             Handle -> BackfillHook . h_Data     = Handle;
  223.  
  224. #ifdef DO_HEXHOOK
  225.             Handle -> HexEditHook . h_Entry     = (HOOKFUNC)LTP_HexEditRoutine;
  226.             Handle -> HexEditHook . h_Data        = Handle;
  227. #endif
  228.  
  229.             if(Handle -> DrawInfo = GetScreenDrawInfo(Screen))
  230.             {
  231.                 LONG i;
  232.  
  233.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  234.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  235.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  236.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  237.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  238.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  239.  
  240.                 if(Handle -> BackgroundPen)
  241.                 {
  242.                     InitBitMap(&Handle->BackfillBitMap,Handle->DrawInfo->dri_Depth,Handle->Screen->Width,Handle->Screen->Width);
  243.  
  244.                     for(i = 0 ; i < Handle->BackfillBitMap.Depth ; i++)
  245.                     {
  246.                         if(Handle->BackgroundPen & (1L << i))
  247.                             Handle->BackfillBitMap.Planes[i] = (PLANEPTR)0xFFFFFFFF;
  248.                         else
  249.                             Handle->BackfillBitMap.Planes[i] = (PLANEPTR)NULL;
  250.                     }
  251.                 }
  252.  
  253.                 if(V39 && MenuGlyphs)
  254.                 {
  255.                     LONG Size,FontHeight = Handle -> DrawInfo -> dri_Font -> tf_Baseline + 2;
  256.  
  257.                     if(Screen -> Flags & SCREENHIRES)
  258.                         Size = SYSISIZE_MEDRES;
  259.                     else
  260.                         Size = SYSISIZE_LOWRES;
  261.  
  262.                     if(Handle -> AmigaGlyph = NewObject(NULL,SYSICLASS,
  263.                         SYSIA_DrawInfo, Handle -> DrawInfo,
  264.                         SYSIA_Size,    Size,
  265.                         SYSIA_Which,    AMIGAKEY,
  266.                         IA_Left,    0,
  267.                         IA_Top,     0,
  268.                         IA_Width,    (FontHeight * 3 * Handle -> AspectY) / (2 * Handle -> AspectX),
  269.                         IA_Height,    FontHeight,
  270.                     TAG_DONE))
  271.                     {
  272.                         if(!(Handle -> CheckGlyph = NewObject(NULL,SYSICLASS,
  273.                             SYSIA_DrawInfo, Handle -> DrawInfo,
  274.                             SYSIA_Size,    Size,
  275.                             SYSIA_Which,    MENUCHECK,
  276.                             IA_Left,    0,
  277.                             IA_Top,     0,
  278.                             IA_Width,    (FontHeight * Handle -> AspectY) / Handle -> AspectX,
  279.                             IA_Height,    FontHeight,
  280.                         TAG_DONE)))
  281.                         {
  282.                             DisposeObject(Handle -> AmigaGlyph);
  283.  
  284.                             Handle -> AmigaGlyph = NULL;
  285.                         }
  286.                     }
  287.                 }
  288.  
  289.                 for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  290.                 {
  291.                     if(Handle -> DrawInfo -> dri_Pens[i] > Handle -> MaxPen)
  292.                         Handle -> MaxPen = Handle -> DrawInfo -> dri_Pens[i];
  293.                 }
  294.  
  295.                 if(Handle -> VisualInfo = GetVisualInfoA(Screen,NULL))
  296.                 {
  297.                     InitRastPort(&Handle -> RPort);
  298.  
  299.                     if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
  300.                     {
  301. #ifdef DO_PICKSHORTCUTS
  302.                         memset(Handle -> Keys,TRUE,256);
  303.  
  304.                         for(i = 0 ; i < 256 ; i++)
  305.                         {
  306.                             if(i != 32 && i != 160)
  307.                             {
  308.                                 if(LTP_Keys[0][i])
  309.                                     Handle -> Keys[LTP_Keys[0][i]] = FALSE;
  310.  
  311.                                 if(LTP_Keys[1][i])
  312.                                     Handle -> Keys[LTP_Keys[1][i]] = FALSE;
  313.                             }
  314.                         }
  315. #endif
  316.                         return(Handle);
  317.                     }
  318.                 }
  319.             }
  320.  
  321.             LT_DeleteHandle(Handle);
  322.         }
  323.         else
  324.             AsmDeletePool(Pool,SysBase);
  325.     }
  326.     else
  327.         UnlockPubScreen(NULL,PubScreen);
  328.  
  329.     return(NULL);
  330. }
  331.